<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of findInDatabase
 *
 * @author 12502
 */
include_once 'php\ld\linkdatabase.php';

class findInDatabase {

    public function findPassword($username, $password) {
        $link = linkdatabase::link();
        @mysqli_select_db($link, "sample");
        $query = "select count(*) from archives where 
             stu_number ='" . $username . "'and password
                 ='" . $password . "'";
        $result = mysqli_query($link, $query);
        if (!$result) {
            echo 'can not run';
        }
        $row = mysqli_fetch_row($result);
        $count = $row[0];
        return $count;
    }

    public static function findName($username) {
        $link = linkdatabase::link();
        @mysqli_select_db($link, "sample");
        $query = "select * from archives where 
             stu_number ='$username' ";
        $result = mysqli_query($link, $query);
        if (!$result) {
            echo "name gg";
        } else {
            $row = mysqli_fetch_array($result);
            $name = $row['name'];
            echo $name;
        }
    }

    public static function findImage($username) {
        $link = linkdatabase::link();
        @mysqli_select_db($link, "sample");
        $query = "select * from archives where 
             stu_number ='$username' ";
        $result = mysqli_query($link, $query);
        if (!$result) {
            echo "image gg";
        } else {
            $row = mysqli_fetch_array($result);
            $image = $row['image'];
           echo $image;
        }
    }

    public function findQuestion($lanuge, $unit, $id) {
        $link = linkdatabase::link();
        @mysqli_select_db($link, "sample");
        $query = "select * from questionbank where id=$id.unit=$unit.classes=$lanuge";
        $result = mysqli_fetch_query($link, $query);
        if (!$result) {
            echo "cannot run";
        }
        $row = mysqli_fetch_row($result);
        $question = array($row['name'], $row['contents']);
        return $question;
    }

}
?>

